var findUrl = "../act/findTasksByUserId";
var startProcessUrl = "../act/startProcess";
var showImageUrl = "../act/showImage";
var applyUrl = "../act/apply";
var showHistoryTaskListUrl="../act/showHistoryTaskList";
var showProcessStateUrl="../act/showProcessState";
/**
 * 查询当前用户名下流程
 */
function findActivitiProcess() {
    var process = $('#processFind').val();
    var userId = $('#userIdFind').val();
    var tmp = "?process=" + process + "&userId=" + userId;
    var findUrlTmp = findUrl + tmp;
    $.ajax({
        url: findUrlTmp,
        data: "",
        dataType: "text",
        success: function (data) {
            outMessage(data);
        },
        error: function () {
            outMessage("出错了");
        }
    });
}

/**
 * 开启一个流程
 */
function startProcess() {
    var process = $('#processStart').val();
    var userId = $('#userIdStart').val();
    var days = $('#daysStart').val();
    var formId = $('#formIdStart').val();
    var tmp = "?process="+process+"&userId="+userId+"&days="+days+"&formId="+formId;
    var findUrlTmp = startProcessUrl + tmp;
    $.ajax({
        url: findUrlTmp,
        data: "",
        dataType: "text",
        success: function (data) {
            outMessage(data);
        },
        error: function () {
            outMessage("出错了");
        }
    });
}

/**
 * 查看流程图
 */
function showImage() {
    var processInstanceId = $('#processInstanceId').val();
    var tmp = "?processInstanceId="+processInstanceId;
    var findUrlTmp = showImageUrl + tmp;
    $('#message').empty();
    var html = "<img src='"+findUrlTmp+"'>";
    $('#message').append(html);
}

/**
 * 审核
 */
function apply() {
    var userId = $('#userIdApp').val();
    var taskId = $('#taskId').val();
    var auditResult = $('#auditResult').val();
    var tmp = "?userId="+userId+"&taskId="+taskId+"&auditResult="+auditResult;
    var findUrlTmp = applyUrl + tmp;
    $.ajax({
        url: findUrlTmp,
        data: "",
        dataType: "text",
        success: function (data) {
            outMessage(data);
        },
        error: function () {
            outMessage("出错了");
        }
    });
}

/**
 * 历史任务查询
 */
function showHistoryTaskList() {
    var processInstanceId = $('#processInstanceId').val();
    var tmp = "?processInstanceId="+processInstanceId;
    var findUrlTmp = showHistoryTaskListUrl + tmp;
    $.ajax({
        url: findUrlTmp,
        data: "",
        dataType: "text",
        success: function (data) {
            outMessage(data);
        },
        error: function () {
            outMessage("出错了");
        }
    });
}

/**
 * 查看流程状态
 */
function showProcessState() {
    var processInstanceId = $('#processInstanceId').val();
    var tmp = "?processInstanceId="+processInstanceId;
    var findUrlTmp = showProcessStateUrl + tmp;
    $.ajax({
        url: findUrlTmp,
        data: "",
        dataType: "text",
        success: function (data) {
            outMessage(data);
        },
        error: function () {
            outMessage("出错了");
        }
    });
}

/**
 * 输出内容
 */
function outMessage(obj) {
    document.getElementById('message').innerText = obj;
}